from wtforms import Form, StringField, IntegerField
from wtforms.validators import Length, NumberRange, DataRequired, Regexp


class SearchForm(Form):
    # 文本字符串形的验证对象(验证规则-> 不能为空,长度最小是1,最大是30)
    q = StringField(validators=[DataRequired(), Length(min=1, max=30)])
    # 验证规则-> 数字,长度,有默认值
    page = IntegerField(validators=[NumberRange(min=1, max=99)], default=1)


class DriftForm(Form):
    recipient_name = StringField(validators=[DataRequired(),
                                             Length(2, 20, message='收件人姓名必须在2-20个字符中间.')])

    mobile = StringField(validators=[DataRequired(),
                                     Regexp('^1[0-9]{10}$', 0, '请输入正确的手机号')])

    message = StringField()

    address = StringField(validators=[DataRequired(),
                                      Length(10, 70, message='地址必须10个字符以上,在详细一点吧!')])